<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>点是否在多边形内</title>
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" type="text/css">
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=8082374df27660645d147f4934a65e90"></script>
    <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
    <style>
        html,body,#container{
            height: 100%
        }
    </style>
</head>
<body>
<div id="container"></div>
<div class='info'>拖动Marker可调整位置</div>
<script type="text/javascript">
    //初始化地图对象，加载地图
    var map = new AMap.Map("container", {
        resizeEnable: true,
        zoom: 13
    });

    // 创建多边形
    var path = [
        [118.177668,39.666801],
        [118.117329,39.668552],
        [118.121448,39.633894],
        [118.177925,39.617631],
        [118.177925,39.617631],
        [118.264786,39.600703],
        [118.256546,39.629399],
        [118.247105,39.667069],
        [118.234573,39.696662],
        [118.173633,39.696134],



    ];
    var polygon = new AMap.Polygon({
        map: map,
        fillOpacity:0.4,
        path: path
    });

    // 创建点
    var marker = new AMap.Marker({
        map: map,
        draggable:true,
        position: [118.185693,39.641458]
    });

    function compute(){
        var point = marker.getPosition();
        var isPointInRing = AMap.GeometryUtil.isPointInRing(point,path);
        marker.setLabel({
            content:isPointInRing?'没有超出范围':'已经超出范围',
            offset:new AMap.Pixel(20,0)
        });
    }

    compute();
    // 为marker绑定拖拽事件
    marker.on('dragging',compute)
    map.setFitView();

</script>
</body>
</html>